<template>
	<view>
		<Header>
			提案工作
		</Header>
		<view class="top-content">
			<view class="item">
				案由：
			</view>
			<view class="item">
				{{data.title}}
			</view>
			<view class="item">
				归类：
			</view>
			<view class="item">
				{{data.case_type_text}}
			</view>
		</view>
		<uni-list>
			<picker class="picker" @change="(res) => bindPickerChange(res, 'pjone')" :value="pjoneIdx"
				:range="pjoneList">
				<uni-list-item showArrow title="对承办单位的总体评价:">
					<template v-slot:footer>
						<view class="uni-content">
							{{pjoneList[pjoneIdx]}}
						</view>
					</template>
				</uni-list-item>
			</picker>
			<picker class="picker" @change="(res) => bindPickerChange(res, 'pjtwo')" :value="pjtwoIdx"
				:range="pjtwoList">
				<uni-list-item showArrow title="提案内容的落实情况:">
					<template v-slot:footer>
						<view class="uni-content">
							{{pjtwoList[pjtwoIdx]}}
						</view>
					</template>
				</uni-list-item>
			</picker>
			<picker class="picker" @change="(res) => bindPickerChange(res, 'zonghepj')" :value="zonghepjIdx"
				:range="zonghepjList">
				<uni-list-item showArrow title="对办理工作的综合评价:">
					<template v-slot:footer>
						<view class="uni-content">
							{{zonghepjList[zonghepjIdx]}}
						</view>
					</template>
				</uni-list-item>
			</picker>
			<uni-list-item>
				<template v-slot:body>
					<view style="width: 100%;">
						对办理工作的其他意见：
						<uni-easyinput type="textarea" autoHeight v-model="remarks" placeholder="请输入"
							class="uni-textarea"></uni-easyinput>
					</view>
				</template>
			</uni-list-item>
		</uni-list>
		<button type="primary" class="submit-btn" @click="submitForm()">提交评价</button>
	</view>
</template>

<script>
	import Header from '../../components/header.vue'
	import request from '../../common/request.js'
	export default {
		components: {
			Header
		},
		data() {
			return {
				id: '',
				data: {},
				pjoneList: [],
				pjoneIdx: '',
				pjtwoList: [],
				pjtwoIdx: '',
				zonghepjList: [],
				zonghepjIdx: '',
				remarks: ''
			}
		},
		onLoad(option) {
			this.id = option.id
		},
		mounted() {
			this.getDetailData()
			this.getDataList()
		},
		methods: {
			submitForm() {
				let param = {
					proposal_id: this.id,
					overall: this.pjoneList[this.pjoneIdx],
					implement: this.pjtwoList[this.pjtwoIdx],
					merit: this.zonghepjList[this.zonghepjIdx],
					remarks: this.remarks
				}
				request({
					url: '/proposal/subEvaluate',
					data: param,
					method: 'POST'
				}).then(res => {
					if (res.code == 1) {
						uni.showToast({
							title: res.msg,
							icon: 'none',
							duration: 2000
						});
						this.timeout = setTimeout(() => {
							uni.navigateBack({
								delta: 1
							});
						}, 2000)
					} else {
						uni.showToast({
							title: res.msg,
							icon: 'none',
							duration: 2000
						});
					}
				})
			},
			bindPickerChange(e, type) {
				switch (type) {
					case 'pjone':
						this.pjoneIdx = e.detail.value
						break;
					case 'pjtwo':
						this.pjtwoIdx = e.detail.value
						break;
					case 'zonghepj':
						this.zonghepjIdx = e.detail.value
						break;
				}
			},
			getDetailData() {
				request({
					url: '/proposal/detail',
					data: {
						proposal_id: this.id
					},
					method: 'POST'
				}).then(res => {
					if (res.code == 1) {
						this.data = res.data

					} else {
						uni.showToast({
							title: res.msg,
							icon: 'none',
							duration: 2000
						});
					}
				})
			},
			getDataList() {
				request({
					url: '/proposal/dataList',
					method: 'POST',
				}).then(res => {
					if (res.code == 1) {
						this.pjoneList = Object.values(res.data[0] && res.data[0].pjoneList)
						this.pjtwoList = Object.values(res.data[0] && res.data[0].pjtwoList)
						this.zonghepjList = Object.values(res.data[0] && res.data[0].zonghepjList)
					}
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.top-content {
		background-color: #2668be;
		color: #fff;
		padding: 20px 10px;
		text-align: center;

		.item {
			margin: 10px 0px;
		}
	}

	.uni-content {
		color: #ea5c55;
	}

	.uni-textarea {
		width: 100%;
		margin: 15px 0px 10px;
	}

	.submit-btn {
		font-size: 14px;
		padding: 5px;
		border-radius: 30px;
		background-color: #2668be;
		margin: 30px 15px;
	}
</style>